<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="./layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<div class="demoTable">

  <div class="layui-inline">
    <input class="layui-input" name="id" id="demoReload" autocomplete="off">
  </div>
  <button class="layui-btn" data-type="reload">搜索</button>
</div>

<table class="layui-hide" id="test" lay-filter="demo"></table>

<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  {{#  if(d.status > '已完成'){ }}
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
   {{#  } }}
</script>              
          
<script src="./layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
 
<script>
layui.use('table', function(){
  var table = layui.table;


   //监听工具条
  table.on('tool(demo)', function(obj){
    var data = obj.data;
    if(obj.event === 'detail'){
      location.href='order.html?id='+data.bid;
      layer.msg('ID：'+ data.bid + ' 的查看操作');
    } else if(obj.event === 'del'){
      layer.confirm('真的删除行么', function(index){
        obj.del();
        layer.close(index);
      });
    } else if(obj.event === 'edit'){
      layer.alert('编辑行：<br>'+ JSON.stringify(data))
    }
  });



   var $ = layui.$,
     active = {
    reload: function(){
      var demoReload = $('#demoReload');
      
      //执行重载
      table.reload('testReload', {
        method:'POST',
        url:'http://127.0.0.1/localhost/zhuchao/tp/public/index.php/index/index/upSave',
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
          key: {
            name: demoReload.val()
          }
        }
      }, 'data');
    }
  };
  


  
  
  table.render({
    elem: '#test'
    ,url:'http://127.0.0.1/localhost/zhuchao/tp/public/index.php/index/index/orders'
    ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
    ,cols: [[
      {field:'bid', width:80, title: 'ID', sort: true}
      ,{field:'b_name', width:80, title: '编号'}
      ,{field:'time', width:80, title: '时间', sort: true}
      ,{field:'status', width:80, title: '状态'}
      ,{fixed: 'right', width:178, align:'center', toolbar: '#barDemo'}
    
    ]]
      ,parseData: function(res){ //res 即为原始返回的数据
        return {
          "code": res.status, //解析接口状态
          "msg": res.msg, //解析提示文本
          "count": res.data.total, //解析数据长度
          "data": res.data //解析数据列表
         };
      }
  });
});
</script>

</body>
</html>